package com.example.example01;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
  private final Text kwriter = new Text();
  private final IntWritable vwriter = new IntWritable(1);
  
  public WordCountMapper(){}

  @Override
  public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
    String rowStr = value.toString();
    if(rowStr == null || rowStr.trim().length() == 0)
      return;
    String[] words = rowStr.split(" ");
    for(String word : words){
      kwriter.set(word);
      context.write(kwriter, vwriter);
    }
  }
}
